package com.ljyh.cygnus.screens.viewmodel

import com.ljyh.cygnus.model.CommandUiState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

class WhitelistViewModel : BaseViewModel() {
    private val _uiState = MutableStateFlow<CommandUiState>(CommandUiState.Loading)
    val uiState: StateFlow<CommandUiState> = _uiState.asStateFlow()

    fun addWhitelist(command: String) {
        executeRootCommands(
            _uiState,
            "iptables -P OUTPUT DROP",
            command
        )
    }

    fun clearWhitelist() {
        executeRootCommands(
            _uiState,
            "iptables -F OUTPUT",
            "iptables -P OUTPUT ACCEPT"
        )
    }
}